package com.jgc.stage01.实现线程方式;

import org.junit.Test;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

/**
 * Created by Administrator on 2022/2/10.
 */

public class Main {
    public static void main(String[] args) {

    }
    @Test //实现方式一、继承Thread接口
    public void testThread() throws InterruptedException {
        MyThread myThread = new MyThread();
        myThread.start();
        myThread.join();
    }
    @Test //实现方式二、实现Runnalbe
    public void testRunnalbe() throws InterruptedException {
        MyRunnable myRunnable = new MyRunnable();
        Thread thread = new Thread(myRunnable);
        thread.start();
        thread.join();
    }
    @Test//实现方式三、实现Callable
    public void testCallable() throws ExecutionException, InterruptedException {
        MyCallable callable = new MyCallable(1);
        FutureTask<Integer> futureTask = new FutureTask<>(callable);
        new Thread(futureTask).start();
        Integer num = futureTask.get();
        System.out.println(num);
    }
}
